//
//  ToolsModel.m
//  UI18_网络封装
//
//  Created by 刘建镇 on 14-12-18.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ToolsModel.h"

@implementation ToolsModel


//存储数据
+ (void)saveFile:(NSData *)data fileName:(NSString *)fileName
{
    NSString *path = [ToolsModel libraryPathWithName:fileName];
    [data writeToFile:path atomically:YES];
}

//取出数据
+ (NSData *)dataWithFileName:(NSString *)fileName
{
    if ([ToolsModel fileExists:fileName]) {
        NSString *path = [ToolsModel libraryPathWithName:fileName];
        NSData *data = [NSData dataWithContentsOfFile:path];
        return  data;
    }
    return [NSData data];
}

//判断是否有这个文件
+ (BOOL)fileExists:(NSString *)fileName
{
    NSString *path = [ToolsModel libraryPathWithName:fileName];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    return [fileManager fileExistsAtPath:path];
}

//寻找文件路径
+ (NSString *)libraryPathWithName:(NSString *)fileName
{
    
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
    path = [NSString stringWithFormat:@"%@/%@", path, fileName];
    return path;
}

@end
